import 'package:json_annotation/json_annotation.dart';

part 'base_response.g.dart';

@JsonSerializable(genericArgumentFactories: true)
class BaseResponse<T> {
  int? code;
  bool? success;
  String? msg;
  T? data;

  //兼容php字段
  int? count;

  BaseResponse({this.code, this.msg, this.success, this.data});

  factory BaseResponse.fromJson(
          Map<String, dynamic> json, T Function(Object? json) fromJsonT) =>
      _$BaseResponseFromJson(json, fromJsonT);

  Map<String, dynamic> toJson(Object? Function(T value) toJsonT) =>
      _$BaseResponseToJson(this, toJsonT);

  isSuccess() {
    return code == 200;
  }

  @override
  String toString() {
    return "BaseResponse<$T> - > \n {code:$code,msg:$msg,data:$data}";
  }
}
